<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8" />

        <title>OpenWrt Sysupgrade Server</title>
        <link href="/static/style.css" rel="stylesheet" />
    </head>
    <body>
        <header>
            <div>
                <img src="/static/logo.png" alt="OpenWrt Firmware logo" />
            </div>
        </header>
        <div class="container">
            <h1>OpenWrt Sysupgrade Server ({{ version }})</h1>

            <div class="grid-container">
                <div class="grid-item">
                    <h2>About the Sysupgrade Server</h2>
                    <p>
                        This server listens for requests to build custom OpenWrt
                        sysupgrade images. It starts an ImageBuilder process for
                        the specified target, incorporates any requested
                        packages, and returns that image to the requestor. The
                        server also provides an
                        <a href="/docs/" target="_blank">API</a> (or
                        <a href="/redoc/" target="_blank">Redoc</a>) for common
                        operations. Learn more on
                        <a href="https://github.com/openwrt/asu" target="_blank"
                            >Github.</a
                        >
                        Please
                        <a
                            href="https://github.com/openwrt/asu/issues"
                            target="_blank"
                            >report issues!</a
                        >
                    </p>
                    <p>
                        <b>How to use this server:</b> There are at least three
                        clients that can request a new image from the Sysupgrade
                        Server:
                    </p>
                    <ul>
                        <li>
                            <a
                                href="https://github.com/openwrt/asu#luci-app"
                                target="_blank"
                                >LuCI Package:</a
                            >
                            <code
                                >opkg install luci-app-attendedsysupgrade</code
                            >
                        </li>
                        <li>
                            <a
                                href="https://github.com/openwrt/asu#cli"
                                target="_blank"
                                >Command line/SSH (OpenWrt >23.xx) :</a
                            >
                            <code>opkg install owut</code>
                        </li>
                        <li>
                            <a
                                href="https://github.com/openwrt/asu#cli"
                                target="_blank"
                                >Command line/SSH:</a
                            >
                            <code>opkg install auc</code>
                        </li>
                    </ul>

                    {% if server_stats %}
                    <div class="grid-item">
                        <h2>Builds per Hour (last 7 days)</h2>
                        <canvas id="buildsChart" width="600" height="300"></canvas>
                    </div>
                    {% endif %}

                    <details>
                        <summary><h2>Server Configuration</h2></summary>

                    <p>
                        <b>Allow custom UCI defaults:</b> {{ defaults }} <br />
                        <b>Maximum requested root filesystem size:</b> {{
                        max_custom_rootfs_size_mb }} MB <br />
                        <b>Available versions on this server:</b>

                    <ul>
                        {% for version in versions %}
                        <li>{{ version }}</li>
                        {%- endfor -%}
                    </ul>
                    </p>

                    </details>
                </div>
            </div>
        </div>

{% if server_stats %}
        <script src="static/chart.js"></script>
        <script>
            async function loadBuildStats() {
                const response = await fetch("/api/v1/builds-per-hour");
                const data = await response.json();

                const countChart = new Chart(document.getElementById("buildsChart"), {
                    type: "line",
                    data: {
                        labels: data.labels,
                        datasets: data.datasets.map(ds => ({
                            data: ds.data,
                            fill: false
                        }))
                    },
                    options: {
                        responsive: true,
                        scales: {
                          x: {
                            display: false
                          },
                          y: {
                            display: true
                          }
                        },
                        plugins: {
                          legend: {
                            display: false
                          },
                            title: { display: false }
                        }
                    }
                });
            }

            loadBuildStats()
        </script>
{% endif %}

    </body>
</html>
